package swordoffer.offer06;

import java.util.*;

public class StackSolution {
    public ArrayList<Integer> printListFromTailToHead(ListNode listNode) {
        Deque<ListNode> stack = new LinkedList<>();
        while(listNode != null){
            stack.addLast(listNode);
            listNode = listNode.next;
        }
        ArrayList<Integer> res = new ArrayList<>();
        while (!stack.isEmpty()){
            res.add(stack.removeLast().val);
        }
        return res;
    }

}